package dipl.algorithm.math.fp.primitive;

/**
 * 3x3 matrix to represent affine transformations in 2d for example
 */
public class Matrix3x3f {

	//
	// CONSTRUCTOR METHODS
	//

	/**
	 * Constructs identity matrix
	 */
	public Matrix3x3f() {
		m = new double[3][];
		m[0] = new double[3];
		m[0][0] = 1.0; m[0][1] = 0.0; m[0][2] = 0.0;
		m[1] = new double[3];
		m[1][0] = 0.0; m[1][1] = 1.0; m[1][2] = 0.0;
		m[2] = new double[3];
		m[2][0] = 0.0; m[2][1] = 0.0; m[2][2] = 1.0;
	}

	//
	// PROPERTIES
	//

	/**
	 * @return determinant
	 */
	public double Determinant() {
		return m[0][0]*(m[2][2]*m[1][1]-m[2][1]*m[1][2])-
					 m[1][0]*(m[2][2]*m[0][1]-m[2][1]*m[0][2])+
					 m[2][0]*(m[1][2]*m[0][1]-m[1][1]*m[0][2]);
	}

	/**
	 * @return whether or not matrix is invertible
	 */
	public boolean Invertible() {
		return (Determinant() != 0.0);
	}

	//
	// MEMBERS
	//

	/**
	 * matrix elements
	 */
	public double[][] m;
}
